﻿using System;
using System.Runtime.Caching;

namespace WeiSha.Core
{
	public class MemoryCache
    {
        private static readonly MemoryCache _default = new MemoryCache();
        public static MemoryCache Default
        {
            get
            {
                return _default;
            }
        }

        private System.Runtime.Caching.MemoryCache _cache;

        public MemoryCache()
        {
            _cache = new System.Runtime.Caching.MemoryCache(Guid.NewGuid().ToString());
        }

        public bool Add(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
        {
            return this._cache.Add(key, value, absoluteExpiration, regionName);
        }

        public void Set(string key, object value, CacheItemPolicy policy, string regionName = null)
        {
            this._cache.Set(key, value, policy, regionName);
        }

        public void Set(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
        {
            this._cache.Add(key, value, absoluteExpiration, regionName);
        }

        public object Get(string cachename)
        {
            return this._cache.Get(cachename, null);
        }

        public object Remove(string cachename)
        {
            return this._cache.Remove(cachename, null);
        }

        public bool Contains(string cachename)
        {
            return this._cache.Contains(cachename, null);
        }
    }
}
